{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 波士顿房价预测案例——线性回归分析\n",
    "\n",
    "在这个案例中，我们将利用波士顿郊区的房屋信息数据训练和测试一个模型，并对模型的性能和预测能力进行测试。\n",
    "\n",
    "该数据集来自UCI机器学习知识库。波士顿房屋这些数据于1978年开始统计，共506个数据点，涵盖了麻省波士顿不同郊区房屋13种特征和房价的信息。\n",
    "\n",
    "本项目将原始数据集存为csv格式，方便调用pandas做数据分析。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1、导入必要的工具包"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np  # 矩阵操作\n",
    "import pandas as pd # SQL数据处理\n",
    "\n",
    "from sklearn.metrics import r2_score  #评价回归预测模型的性能\n",
    "\n",
    "import matplotlib.pyplot as plt   #画图\n",
    "import seaborn as sns\n",
    "\n",
    "# 图形出现在Notebook里而不是新窗口\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2、数据探索"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.1 读取数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CRIM</th>\n",
       "      <th>ZN</th>\n",
       "      <th>INDUS</th>\n",
       "      <th>CHAS</th>\n",
       "      <th>NOX</th>\n",
       "      <th>RM</th>\n",
       "      <th>AGE</th>\n",
       "      <th>DIS</th>\n",
       "      <th>RAD</th>\n",
       "      <th>TAX</th>\n",
       "      <th>PTRATIO</th>\n",
       "      <th>B</th>\n",
       "      <th>LSTAT</th>\n",
       "      <th>MEDV</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.00632</td>\n",
       "      <td>18</td>\n",
       "      <td>2.31</td>\n",
       "      <td>0</td>\n",
       "      <td>0.538</td>\n",
       "      <td>6.575</td>\n",
       "      <td>65.2</td>\n",
       "      <td>4.0900</td>\n",
       "      <td>1</td>\n",
       "      <td>296</td>\n",
       "      <td>15</td>\n",
       "      <td>396.90</td>\n",
       "      <td>4.98</td>\n",
       "      <td>24.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.02731</td>\n",
       "      <td>0</td>\n",
       "      <td>7.07</td>\n",
       "      <td>0</td>\n",
       "      <td>0.469</td>\n",
       "      <td>6.421</td>\n",
       "      <td>78.9</td>\n",
       "      <td>4.9671</td>\n",
       "      <td>2</td>\n",
       "      <td>242</td>\n",
       "      <td>17</td>\n",
       "      <td>396.90</td>\n",
       "      <td>9.14</td>\n",
       "      <td>21.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.02729</td>\n",
       "      <td>0</td>\n",
       "      <td>7.07</td>\n",
       "      <td>0</td>\n",
       "      <td>0.469</td>\n",
       "      <td>7.185</td>\n",
       "      <td>61.1</td>\n",
       "      <td>4.9671</td>\n",
       "      <td>2</td>\n",
       "      <td>242</td>\n",
       "      <td>17</td>\n",
       "      <td>392.83</td>\n",
       "      <td>4.03</td>\n",
       "      <td>34.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.03237</td>\n",
       "      <td>0</td>\n",
       "      <td>2.18</td>\n",
       "      <td>0</td>\n",
       "      <td>0.458</td>\n",
       "      <td>6.998</td>\n",
       "      <td>45.8</td>\n",
       "      <td>6.0622</td>\n",
       "      <td>3</td>\n",
       "      <td>222</td>\n",
       "      <td>18</td>\n",
       "      <td>394.63</td>\n",
       "      <td>2.94</td>\n",
       "      <td>33.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.06905</td>\n",
       "      <td>0</td>\n",
       "      <td>2.18</td>\n",
       "      <td>0</td>\n",
       "      <td>0.458</td>\n",
       "      <td>7.147</td>\n",
       "      <td>54.2</td>\n",
       "      <td>6.0622</td>\n",
       "      <td>3</td>\n",
       "      <td>222</td>\n",
       "      <td>18</td>\n",
       "      <td>396.90</td>\n",
       "      <td>5.33</td>\n",
       "      <td>36.2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      CRIM  ZN  INDUS  CHAS    NOX     RM   AGE     DIS  RAD  TAX  PTRATIO  \\\n",
       "0  0.00632  18   2.31     0  0.538  6.575  65.2  4.0900    1  296       15   \n",
       "1  0.02731   0   7.07     0  0.469  6.421  78.9  4.9671    2  242       17   \n",
       "2  0.02729   0   7.07     0  0.469  7.185  61.1  4.9671    2  242       17   \n",
       "3  0.03237   0   2.18     0  0.458  6.998  45.8  6.0622    3  222       18   \n",
       "4  0.06905   0   2.18     0  0.458  7.147  54.2  6.0622    3  222       18   \n",
       "\n",
       "        B  LSTAT  MEDV  \n",
       "0  396.90   4.98  24.0  \n",
       "1  396.90   9.14  21.6  \n",
       "2  392.83   4.03  34.7  \n",
       "3  394.63   2.94  33.4  \n",
       "4  396.90   5.33  36.2  "
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# path to where the data lies\n",
    "#dpath = './data/'\n",
    "data = pd.read_csv(\"boston_housing.csv\")\n",
    "\n",
    "#通过观察前5行，了解数据每列（特征）的概况\n",
    "data.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "###  2.2 数据基本信息\n",
    "样本数目、特征维数\n",
    "每个特征的类型、空值样本的数目、数据类型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(506, 14)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.3 数据探索\n",
    "请见另一个文件：FE_BostonHousePrice.pynb\n",
    "\n",
    "对数据的探索有助于我们在第三步中根据数据的特点选择合适的模型类型"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.4 数据准备"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": true,
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "# 从原始数据中分离输入特征x和输出y\n",
    "y = data['MEDV'].values\n",
    "X = data.drop('MEDV', axis = 1)\n",
    "\n",
    "#用于后续显示权重系数对应的特征\n",
    "columns = X.columns"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "当数据量比较大时，可用train_test_split从训练集中分出一部分做校验集；\n",
    "样本数目较少时，建议用交叉验证\n",
    "在线性回归中，留一交叉验证有简便计算方式，无需显式交叉验证\n",
    "\n",
    "下面将训练数据分割成训练集和测试集，只是让大家对模型的训练误差、校验集上的测试误差估计、和测试集上的测试误差做个比较，实际任务中无需这么处理。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(404, 13)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#将数据分割训练数据与测试数据\n",
    "from sklearn.model_selection import train_test_split\n",
    "\n",
    "# 随机采样20%的数据构建测试样本，其余作为训练样本\n",
    "X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=33, test_size=0.2)\n",
    "X_train.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.5 数据预处理／特征工程\n",
    "\n",
    "特征工程是实际任务中特别重要的环节。\n",
    "\n",
    "scikit learn中提供的数据预处理功能：\n",
    "http://scikit-learn.org/stable/modules/preprocessing.html\n",
    "http://scikit-learn.org/stable/modules/classes.html#module- sklearn.feature_extraction"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#发现各特征差异较大，需要进行数据标准化预处理\n",
    "#标准化的目的在于避免原始特征值差异过大，导致训练得到的参数权重不归一，无法比较各特征的重要性"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": true,
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "# 数据标准化\n",
    "from sklearn.preprocessing import StandardScaler\n",
    "\n",
    "# 分别初始化对特征和目标值的标准化器\n",
    "ss_X = StandardScaler()\n",
    "ss_y = StandardScaler()\n",
    "\n",
    "# 分别对训练和测试数据的特征以及目标值进行标准化处理\n",
    "X_train = ss_X.fit_transform(X_train)\n",
    "X_test = ss_X.transform(X_test)\n",
    "\n",
    "#对y做标准化不是必须\n",
    "#对y标准化的好处是不同问题的w差异不太大，同时正则参数的范围也有限\n",
    "y_train = ss_y.fit_transform(y_train.reshape(-1, 1))\n",
    "y_test = ss_y.transform(y_test.reshape(-1, 1))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3、确定模型类型"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.1 尝试缺省参数的线性回归"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>coef</th>\n",
       "      <th>columns</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>[0.305308916814]</td>\n",
       "      <td>RM</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>[0.294294197295]</td>\n",
       "      <td>RAD</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>[0.132381964846]</td>\n",
       "      <td>ZN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>[0.0824451197457]</td>\n",
       "      <td>CHAS</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>[0.0801587411003]</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>[0.0252062976876]</td>\n",
       "      <td>INDUS</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>[-0.00429841001681]</td>\n",
       "      <td>AGE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>[-0.106437772942]</td>\n",
       "      <td>CRIM</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>[-0.17705123412]</td>\n",
       "      <td>NOX</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>[-0.18931584686]</td>\n",
       "      <td>PTRATIO</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>[-0.245689768489]</td>\n",
       "      <td>TAX</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>[-0.337262451147]</td>\n",
       "      <td>DIS</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>[-0.433408283377]</td>\n",
       "      <td>LSTAT</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   coef  columns\n",
       "5      [0.305308916814]       RM\n",
       "8      [0.294294197295]      RAD\n",
       "1      [0.132381964846]       ZN\n",
       "3     [0.0824451197457]     CHAS\n",
       "11    [0.0801587411003]        B\n",
       "2     [0.0252062976876]    INDUS\n",
       "6   [-0.00429841001681]      AGE\n",
       "0     [-0.106437772942]     CRIM\n",
       "4      [-0.17705123412]      NOX\n",
       "10     [-0.18931584686]  PTRATIO\n",
       "9     [-0.245689768489]      TAX\n",
       "7     [-0.337262451147]      DIS\n",
       "12    [-0.433408283377]    LSTAT"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 线性回归\n",
    "#class sklearn.linear_model.LinearRegression(fit_intercept=True, normalize=False, copy_X=True, n_jobs=1)\n",
    "from sklearn.linear_model import LinearRegression\n",
    "\n",
    "# 使用默认配置初始化\n",
    "lr = LinearRegression()\n",
    "\n",
    "# 训练模型参数\n",
    "lr.fit(X_train, y_train)\n",
    "\n",
    "# 预测\n",
    "y_test_pred_lr = lr.predict(X_test)\n",
    "y_train_pred_lr = lr.predict(X_train)\n",
    "\n",
    "\n",
    "# 看看各特征的权重系数，系数的绝对值大小可视为该特征的重要性\n",
    "fs = pd.DataFrame({\"columns\":list(columns), \"coef\":list((lr.coef_.T))})\n",
    "fs.sort_values(by=['coef'],ascending=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 3.1.1 模型评价"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The r2 score of LinearRegression on test is 0.69029595509\n",
      "The r2 score of LinearRegression on train is 0.745144836731\n"
     ]
    }
   ],
   "source": [
    "# 使用r2_score评价模型在测试集和训练集上的性能，并输出评估结果\n",
    "#测试集\n",
    "print 'The r2 score of LinearRegression on test is', r2_score(y_test, y_test_pred_lr)\n",
    "#训练集\n",
    "print 'The r2 score of LinearRegression on train is', r2_score(y_train, y_train_pred_lr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAekAAAFsCAYAAADos0H8AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAHMZJREFUeJzt3X+8VXWd7/HXRzhCI4qioAgaWFr+\nBOxIkGkUlU6YOI+ptOsPfIhaWvOwuv3QutXJqSmvXrt5te4w/VDTEnUqnRrv6CUZ0lsaGPkLCzKZ\nQAKk/IFlAn7uH3vBHOH82OcX+3vOeT0fj/3Ye6+19lqf71oH3ue71vesHZmJJEkqzy6NLkCSJLXN\nkJYkqVCGtCRJhTKkJUkqlCEtSVKhDGlJkgplSGvQi4hHImJGo+topIj4m4j4XURsjIgpO3G7GyPi\noHbmnR0R9/TSdp6IiLf2xrqkncmQ1oDW1n/O2//nn5mHZ+bCTtYzISIyIob2UamNdgXwwcwckZm/\n2H5m1fbnq1BdHRFXRsSQnm602t7jPV2PNFAZ0lIBCgj/VwKPdLLMpMwcAbwJOBU4p8+rkgY5Q1qD\nXuvedkRMjYjFEfFsRKyNiCurxRZVz09XvcnpEbFLRPy3iFgZEesi4vqIGNlqvWdV8zZExKe3205L\nRNwaETd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kjjjiC+fPnA7Ve7NZbQH/rW9/ikEMO4U1vehP33nvvtvWdffbZ3HrrrdvejxgxAoCNGzcy\nc+ZMjj76aI488khuu+22HWpbs2YNxx9/PJMnT+aII47gJz/5SV1tWrhwISeddBIALS0tnHPOOcyY\nMYODDjroZeF9ww03MHXqVCZPnsz73ve+bcF7wQUX0NzczOGHH75tH0DtlteXXnopb3zjG7nlllvq\nqqVeXTnd/ebMfKrV+4uBBZn5pYi4uHr/iV6tTpK0023ZsoUFCxYwd+5cAO68806WL1/O/fffT2Zy\n8skns2jRItavX8/+++/Pj370IwCeeeaZl61nzZo1fPazn2XJkiWMHDmSN7/5zUyZMqXDbQ8fPpzv\nf//77LHHHjz11FNMmzaNk08++WWDsL7zne9wwgkn8KlPfYotW7bwpz/9qVvtfOyxx7j77rt57rnn\neM1rXsMFF1zAihUrmD9/Pvfeey9NTU1ceOGF3HjjjZx11ll84QtfYNSoUWzZsoWZM2fy4IMPctRR\nR22r+5577ulWHR3pyTXp2cCM6vV1wEIMaUnqt/785z8zefJknnjiCV73utfxtre9DaiF9J133rkt\nYDdu3Mjy5cs57rjj+OhHP8onPvEJTjrpJI477riXre++++5jxowZjB5d+8KnU089lV//+tcd1pCZ\nfPKTn2TRokXssssurF69mrVr17LffvttW+aYY47hnHPOYdOmTZxyyilMnjy5W+2dNWsWw4YNY9iw\nYYwZM4a1a9eyYMEClixZwjHHHLNtn4wZMwaAm2++mXnz5rF582bWrFnDo48+ui2kTz311G7V0Jl6\nr0kncGdELImI86tp+2bmGoDqeUxfFChJ2jm2XpNeuXIlL7744rZr0pnJJZdcwtKlS1m6dCkrVqxg\n7ty5HHLIISxZsoQjjzySSy65hEsvvXSHdbb3Z0hDhw7lpZde2rb+F198EYAbb7yR9evXs2TJEpYu\nXcq+++67w98aH3/88SxatIhx48Zx5plncv3113ervcOGDdv2esiQIWzevJnMZM6cOdva+qtf/YqW\nlhZ++9vfcsUVV7BgwQIefPBBZs2a9bK6dtttt27V0Jl6e9LHZ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q7en5+/rU473hoRB7Qx\nvz/pT/9m6jU9In4ZEXdExOGNLqZe1aWgKcB9283qt8eogzZBPz1OnenJbUGLFxH/F9ivjVmfyszb\n6llFG9Ma9jdrHbWnC6s5MDOfjIiDgB9HxEOZ+ZveqbDH6tnfRR2TTtRT678A383Mv0TE+6mdJXhL\nn1fWd/rT8anHA9Tus7wxIt4B/AA4uME1dSoiRgD/DHwoM5/dfnYbHyn+GHXSpn55nOoxoEM6M9/a\nw1UUdevTjtoTEWsjYmxmrqlOXa1rZx1PVs+PR8RCar+VlhLS9ezvrcusioihwEjKPV3ZaXsyc0Or\nt/8EXLYT6upLRf2b6anWYZCZ/xoRX42IfTKz2C91iIgmamF2Y2Z+r41F+t0x6qxN/fE41cvT3R3r\nT7c+vR2YU72eA+xwpiAi9oqIYdXrfYBjgUd3WoWdq2d/t27nu4AfZzVypECdtme7a4EnU7ve1p/d\nDpxVjSCeBjyz9TJMfxQR+20d8xARU6n9n7mh4081TlXrN4BlmXllO4v1q2NUT5v623HqkkaPXGvU\nA/gbar9R/gVYC/xbNX1/4F9bLfcOaqMJf0PtNHnDa2+nPXsDC4Dl1fOoanoz8PXq9RuAh6iNMn4I\nmNvouttoxw77G7gUOLl6PRy4BVgB3A8c1Oiae9ieLwKPVMfkbuC1ja65k/Z8F1gDbKr+/cwF3g+8\nv5ofwDVVex+inb+cKOVRR3s+2Or4/Ax4Q6Nr7qQ9b6R26vpBYGn1eEc/P0b1tKlfHaeuPLwtqCRJ\nhfJ0tyRJhTKkJUkqlCEtSVKhDGlJkgplSEuSVChDWpKkQhnSkiQV6v8DekScePLvvXUAAAAASUVO\nRK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1a17f4c4d0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#在训练集上观察预测残差的分布，看是否符合模型假设：噪声为0均值的高斯噪声\n",
    "f, ax = plt.subplots(figsize=(7, 5)) \n",
    "f.tight_layout() \n",
    "ax.hist(y_train - y_train_pred_lr,bins=40, label='Residuals Linear', color='b', alpha=.5); \n",
    "ax.set_title(\"Histogram of Residuals\") \n",
    "ax.legend(loc='best');"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "残差分布和高斯分布比较匹配，但还是左skew，可能是由于数据集中有16个数据的y值为最大值，有噪声（预测残差超过2.5）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAARgAAADQCAYAAADcQn7hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAIABJREFUeJztnXt4VOW1uN81kwmZBCTcLxFELYIg\nCBRBK9ZaL1hbEa31iu1RlNKjrWJLC9Uqnh4rltraU/3V0opY5Vi8NQpeEASPLYoIJohUsWLVGqyA\nSYCQQCaT9ftjZtJJMpc9mT0zuaz3eeZh9p69v28lZK9Z31rrW0tUFcMwjEzgybUAhmF0XkzBGIaR\nMUzBGIaRMUzBGIaRMUzBGIaRMUzBGIaRMUzBGIaRMUzBGIaRMUzBGIaRMfJyLUAq9O3bV4cNG5Zr\nMQyjy7N58+Y9qtov2XUdSsEMGzaMTZs25VoMw+jyiMiHTq6zJZJhGBnDFIxhGBkjZwpGRApEZKOI\nbBGRbSJyW65kMQwjM+TSB3MI+LKq1oiID/iriDynqhtyKJNhGC6SMwtGQ9SED33hlxWnMYwcUFdX\nR3l5uevj5tQHIyJeESkHdgGrVfW1GNfMEpFNIrJp9+7d2RfSMDo5ZWVlTJw4kbPOOouamprkN6RA\nThWMqgZVdRxwODBJRI6Lcc1iVZ2oqhP79UsadjcMwyHBYJCFCxcyefJkqqqqeOihh+jevburc7SL\nKJKqVgMvAWfnWBTD6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OfAy+HKa4tSnM/IARamNrKOiFwNHKeqN+RaFiOzmAVjGEbGMAvGMIyMYRaMYRgZ\nwxSMYRgZwxSMYRgZwxSMYRgZwxSMYRgZ4/8D4D5WVIPOFXkAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1a204ca150>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#还可以观察预测值与真值的散点图\n",
    "plt.figure(figsize=(4, 3))\n",
    "plt.scatter(y_train, y_train_pred_lr)\n",
    "plt.plot([-3, 3], [-3, 3], '--k')   #数据已经标准化，3倍标准差即可\n",
    "plt.axis('tight')\n",
    "plt.xlabel('True price')\n",
    "plt.ylabel('Predicted price')\n",
    "plt.tight_layout()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "在y的真值大的部分预测效果不好"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/qing/anaconda2/lib/python2.7/site-packages/sklearn/utils/validation.py:578: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
      "  y = column_or_1d(y, warn=True)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([-0.10590526,  0.13217071,  0.02569317,  0.08194273, -0.17679726,\n",
       "        0.30424453, -0.00361887, -0.3379107 ,  0.29470892, -0.24468694,\n",
       "       -0.18879496,  0.0795581 , -0.43238204])"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 线性模型，随机梯度下降优化模型参数\n",
    "# 随机梯度下降一般在大数据集上应用，其实本项目不适合用\n",
    "from sklearn.linear_model import SGDRegressor\n",
    "\n",
    "# 使用默认配置初始化线\n",
    "sgdr = SGDRegressor(max_iter=1000)\n",
    "\n",
    "# 训练：参数估计\n",
    "sgdr.fit(X_train, y_train)\n",
    "\n",
    "# 预测\n",
    "#sgdr_y_predict = sgdr.predict(X_test)\n",
    "\n",
    "sgdr.coef_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The value of default measurement of SGDRegressor on test is 0.69086051951\n",
      "The value of default measurement of SGDRegressor on train is 0.745117972699\n"
     ]
    }
   ],
   "source": [
    "# 使用SGDRegressor模型自带的评估模块(评价准则为r2_score)，并输出评估结果\n",
    "print 'The value of default measurement of SGDRegressor on test is', sgdr.score(X_test, y_test)\n",
    "print 'The value of default measurement of SGDRegressor on train is', sgdr.score(X_train, y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#这里由于样本数不多，SGDRegressor可能不如LinearRegression。 sklearn建议样本数超过10万采用SGDRegressor"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.2 正则化的线性回归（L2正则 --> 岭回归）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The r2 score of RidgeCV on test is 0.696520650415\n",
      "The r2 score of RidgeCV on train is 0.743912370811\n"
     ]
    }
   ],
   "source": [
    "#岭回归／L2正则\n",
    "#class sklearn.linear_model.RidgeCV(alphas=(0.1, 1.0, 10.0), fit_intercept=True, \n",
    "#                                  normalize=False, scoring=None, cv=None, gcv_mode=None, \n",
    "#                                  store_cv_values=False)\n",
    "from sklearn.linear_model import  RidgeCV\n",
    "\n",
    "#设置超参数（正则参数）范围\n",
    "alphas = [ 0.01, 0.1, 1, 10,100]\n",
    "#n_alphas = 20\n",
    "#alphas = np.logspace(-5,2,n_alphas)\n",
    "\n",
    "#生成一个RidgeCV实例\n",
    "ridge = RidgeCV(alphas=alphas, store_cv_values=True)  \n",
    "\n",
    "#模型训练\n",
    "ridge.fit(X_train, y_train)    \n",
    "\n",
    "#预测\n",
    "y_test_pred_ridge = ridge.predict(X_test)\n",
    "y_train_pred_ridge = ridge.predict(X_train)\n",
    "\n",
    "\n",
    "# 评估，使用r2_score评价模型在测试集和训练集上的性能\n",
    "print 'The r2 score of RidgeCV on test is', r2_score(y_test, y_test_pred_ridge)\n",
    "print 'The r2 score of RidgeCV on train is', r2_score(y_train, y_train_pred_ridge)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 可视化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZgAAAEKCAYAAAAvlUMdAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAIABJREFUeJzt3Xt8HfV55/HPV5JtAjYQfOFiAzbB\nXEwwxghyIYFAoDUksUMCNmxpk5aUTbZs2+XVbsiyS3fZZneB3SabDd0NaWjTNg2WTS4mmEAAB0iL\nEx3fsY2xY4IlbLCwwcZ3S3r2j/nJjMWRJV9GRzr6vl+v89LMb36/mWeOLT1nLucZRQRmZmZHWk2l\nAzAzs+rkBGNmZoVwgjEzs0I4wZiZWSGcYMzMrBBOMGZmVggnGDMzK4QTjJmZFcIJxszMClFX6QAq\nacSIETF27NhKh2Fm1q8sWLDgjYgY2V2/AZ1gxo4dS6lUqnQYZmb9iqRXetLPp8jMzKwQTjBmZlYI\nJxgzMyuEE4yZmRXCCcbMzArhBGNmZoVwgjEzs0I4wZiZDTBff/Il5q/dVPh2nGDMzAaQdZt28PUn\nV9P48ubCt+UEY2Y2gMxe0IQE19ePKXxbTjBmZgNEW3swa0Ezl40fycnHvafw7TnBmJk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ain": [
       "<matplotlib.figure.Figure at 0x1a204cad90>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('alpha is:', 10.0)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>coef_lr</th>\n",
       "      <th>coef_ridge</th>\n",
       "      <th>columns</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>[0.305308916814]</td>\n",
       "      <td>[0.314009523053]</td>\n",
       "      <td>RM</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>[0.294294197295]</td>\n",
       "      <td>[0.223751339446]</td>\n",
       "      <td>RAD</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>[0.132381964846]</td>\n",
       "      <td>[0.113572191287]</td>\n",
       "      <td>ZN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>[0.0824451197457]</td>\n",
       "      <td>[0.0857420083587]</td>\n",
       "      <td>CHAS</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>[0.0801587411003]</td>\n",
       "      <td>[0.0799706938556]</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>[0.0252062976876]</td>\n",
       "      <td>[-0.000691851728079]</td>\n",
       "      <td>INDUS</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>[-0.00429841001681]</td>\n",
       "      <td>[-0.00946358935282]</td>\n",
       "      <td>AGE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>[-0.106437772942]</td>\n",
       "      <td>[-0.0978178053456]</td>\n",
       "      <td>CRIM</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>[-0.17705123412]</td>\n",
       "      <td>[-0.149113779561]</td>\n",
       "      <td>NOX</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>[-0.18931584686]</td>\n",
       "      <td>[-0.182905246466]</td>\n",
       "      <td>PTRATIO</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>[-0.245689768489]</td>\n",
       "      <td>[-0.177674569446]</td>\n",
       "      <td>TAX</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>[-0.337262451147]</td>\n",
       "      <td>[-0.304396020874]</td>\n",
       "      <td>DIS</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>[-0.433408283377]</td>\n",
       "      <td>[-0.417436382241]</td>\n",
       "      <td>LSTAT</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                coef_lr            coef_ridge  columns\n",
       "5      [0.305308916814]      [0.314009523053]       RM\n",
       "8      [0.294294197295]      [0.223751339446]      RAD\n",
       "1      [0.132381964846]      [0.113572191287]       ZN\n",
       "3     [0.0824451197457]     [0.0857420083587]     CHAS\n",
       "11    [0.0801587411003]     [0.0799706938556]        B\n",
       "2     [0.0252062976876]  [-0.000691851728079]    INDUS\n",
       "6   [-0.00429841001681]   [-0.00946358935282]      AGE\n",
       "0     [-0.106437772942]    [-0.0978178053456]     CRIM\n",
       "4      [-0.17705123412]     [-0.149113779561]      NOX\n",
       "10     [-0.18931584686]     [-0.182905246466]  PTRATIO\n",
       "9     [-0.245689768489]     [-0.177674569446]      TAX\n",
       "7     [-0.337262451147]     [-0.304396020874]      DIS\n",
       "12    [-0.433408283377]     [-0.417436382241]    LSTAT"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mse_mean = np.mean(ridge.cv_values_, axis = 0)\n",
    "plt.plot(np.log10(alphas), mse_mean.reshape(len(alphas),1)) \n",
    "\n",
    "#这是为了标出最佳参数的位置，不是必须\n",
    "#plt.plot(np.log10(ridge.alpha_)*np.ones(3), [0.28, 0.29, 0.30])\n",
    "\n",
    "plt.xlabel('log(alpha)')\n",
    "plt.ylabel('mse')\n",
    "plt.show()\n",
    "\n",
    "print ('alpha is:', ridge.alpha_)\n",
    "\n",
    "# 看看各特征的权重系数，系数的绝对值大小可视为该特征的重要性\n",
    "fs = pd.DataFrame({\"columns\":list(columns), \"coef_lr\":list((lr.coef_.T)), \"coef_ridge\":list((ridge.coef_.T))})\n",
    "fs.sort_values(by=['coef_lr'],ascending=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.3 正则化的线性回归（L1正则 --> Lasso）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The r2 score of LassoCV on test is 0.690940649734\n",
      "The r2 score of LassoCV on train is 0.745108399363\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/qing/anaconda2/lib/python2.7/site-packages/sklearn/linear_model/coordinate_descent.py:1094: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
      "  y = column_or_1d(y, warn=True)\n"
     ]
    }
   ],
   "source": [
    "#### Lasso／L1正则\n",
    "# class sklearn.linear_model.LassoCV(eps=0.001, n_alphas=100, alphas=None, fit_intercept=True, \n",
    "#                                    normalize=False, precompute=’auto’, max_iter=1000, \n",
    "#                                    tol=0.0001, copy_X=True, cv=None, verbose=False, n_jobs=1,\n",
    "#                                    positive=False, random_state=None, selection=’cyclic’)\n",
    "from sklearn.linear_model import LassoCV\n",
    "\n",
    "#设置超参数搜索范围\n",
    "#alphas = [ 0.01, 0.1, 1, 10,100]\n",
    "\n",
    "#生成一个LassoCV实例\n",
    "#lasso = LassoCV(alphas=alphas)  \n",
    "lasso = LassoCV()  \n",
    "\n",
    "#训练（内含CV）\n",
    "lasso.fit(X_train, y_train)  \n",
    "\n",
    "#测试\n",
    "y_test_pred_lasso = lasso.predict(X_test)\n",
    "y_train_pred_lasso = lasso.predict(X_train)\n",
    "\n",
    "\n",
    "# 评估，使用r2_score评价模型在测试集和训练集上的性能\n",
    "print 'The r2 score of LassoCV on test is', r2_score(y_test, y_test_pred_lasso)\n",
    "print 'The r2 score of LassoCV on train is', r2_score(y_train, y_train_pred_lasso)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAEKCAYAAAAIO8L1AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAIABJREFUeJzt3Xt4HPV97/H3V3dblnyTZBvJd2SM\nuTgQYZJAEgghMWkOToA0kKRJaBt6CU0vJ6eFkzwkJc1p0/Skp01JUppS2rQNUCCtkxoI4RJCLmAZ\nMNj4IiHbsWzJknzR1brtfs8fOzJreWWtjGZnV/q8nmcf78z8dvY7Wms/mpnf/MbcHRERkdHyoi5A\nRESykwJCRERSUkCIiEhKCggREUlJASEiIikpIEREJCUFhIiIpKSAEBGRlBQQIiKSUkHUBUxURUWF\nL1u2LOoyRERyypYtWzrc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zszeBMSAVUnt20gMXyGSMQoImY7GuknK6W6ecpzEWDaY\n2XLgs8Al7n7UzO4dWTaO5HFtBoJ/Y7z+e/iHJMYzWkti774/qX1JUINIxugQk0xHzwAfNrP84LzA\nO0gMXvYscH1wLmIBJw/nvgM4O3heDvQCnUG7a8Z4nzwSo2YCfCRY/+nMBlqCPZhfI3EbyRGryN3R\nXCVHaQ9CpqPvkTi/sJXEX/V/7O6tZvYQcBWJL+LdwHMk7roFiXuCXAH8yN23mtmLJEZZbQJ+Osb7\n9ALnmdmWYD0fHqeubwAPmdmHgKeC14+4MqhBJGM0mqtIEjOb5e49ZjafxF7FZUF4zCDxpX1ZcO4i\nnXX1uPusSarrGWCDJ+5/LpIR2oMQOdkPzGwOUAR8yd1bAdz9uJl9gcR9fX+ZyYKCw2BfUzhIpmkP\nQkREUtJJahERSUkBISIiKSkgREQkJQWEiIikpIAQEZGUFBAiIpLS/wdQt5LguqrjZgAAAABJRU5E\nrkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1a2062efd0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('alpha is:', 0.00073726292123262299)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>coef_lasso</th>\n",
       "      <th>coef_lr</th>\n",
       "      <th>coef_ridge</th>\n",
       "      <th>columns</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0.305918</td>\n",
       "      <td>[0.305308916814]</td>\n",
       "      <td>[0.314009523053]</td>\n",
       "      <td>RM</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>0.282004</td>\n",
       "      <td>[0.294294197295]</td>\n",
       "      <td>[0.223751339446]</td>\n",
       "      <td>RAD</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.129133</td>\n",
       "      <td>[0.132381964846]</td>\n",
       "      <td>[0.113572191287]</td>\n",
       "      <td>ZN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.082539</td>\n",
       "      <td>[0.0824451197457]</td>\n",
       "      <td>[0.0857420083587]</td>\n",
       "      <td>CHAS</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>0.079412</td>\n",
       "      <td>[0.0801587411003]</td>\n",
       "      <td>[0.0799706938556]</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.018266</td>\n",
       "      <td>[0.0252062976876]</td>\n",
       "      <td>[-0.000691851728079]</td>\n",
       "      <td>INDUS</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>-0.003027</td>\n",
       "      <td>[-0.00429841001681]</td>\n",
       "      <td>[-0.00946358935282]</td>\n",
       "      <td>AGE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>-0.104463</td>\n",
       "      <td>[-0.106437772942]</td>\n",
       "      <td>[-0.0978178053456]</td>\n",
       "      <td>CRIM</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>-0.172111</td>\n",
       "      <td>[-0.17705123412]</td>\n",
       "      <td>[-0.149113779561]</td>\n",
       "      <td>NOX</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>-0.187925</td>\n",
       "      <td>[-0.18931584686]</td>\n",
       "      <td>[-0.182905246466]</td>\n",
       "      <td>PTRATIO</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>-0.233262</td>\n",
       "      <td>[-0.245689768489]</td>\n",
       "      <td>[-0.177674569446]</td>\n",
       "      <td>TAX</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>-0.332661</td>\n",
       "      <td>[-0.337262451147]</td>\n",
       "      <td>[-0.304396020874]</td>\n",
       "      <td>DIS</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>-0.433493</td>\n",
       "      <td>[-0.433408283377]</td>\n",
       "      <td>[-0.417436382241]</td>\n",
       "      <td>LSTAT</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    coef_lasso              coef_lr            coef_ridge  columns\n",
       "5     0.305918     [0.305308916814]      [0.314009523053]       RM\n",
       "8     0.282004     [0.294294197295]      [0.223751339446]      RAD\n",
       "1     0.129133     [0.132381964846]      [0.113572191287]       ZN\n",
       "3     0.082539    [0.0824451197457]     [0.0857420083587]     CHAS\n",
       "11    0.079412    [0.0801587411003]     [0.0799706938556]        B\n",
       "2     0.018266    [0.0252062976876]  [-0.000691851728079]    INDUS\n",
       "6    -0.003027  [-0.00429841001681]   [-0.00946358935282]      AGE\n",
       "0    -0.104463    [-0.106437772942]    [-0.0978178053456]     CRIM\n",
       "4    -0.172111     [-0.17705123412]     [-0.149113779561]      NOX\n",
       "10   -0.187925     [-0.18931584686]     [-0.182905246466]  PTRATIO\n",
       "9    -0.233262    [-0.245689768489]     [-0.177674569446]      TAX\n",
       "7    -0.332661    [-0.337262451147]     [-0.304396020874]      DIS\n",
       "12   -0.433493    [-0.433408283377]     [-0.417436382241]    LSTAT"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mses = np.mean(lasso.mse_path_, axis = 1)\n",
    "plt.plot(np.log10(lasso.alphas_), mses) \n",
    "#plt.plot(np.log10(lasso.alphas_)*np.ones(3), [0.3, 0.4, 1.0])\n",
    "plt.xlabel('log(alpha)')\n",
    "plt.ylabel('mse')\n",
    "plt.show()    \n",
    "            \n",
    "print ('alpha is:', lasso.alpha_)\n",
    "\n",
    "# 看看各特征的权重系数，系数的绝对值大小可视为该特征的重要性\n",
    "fs = pd.DataFrame({\"columns\":list(columns), \"coef_lr\":list((lr.coef_.T)), \"coef_ridge\":list((ridge.coef_.T)), \"coef_lasso\":list((lasso.coef_.T))})\n",
    "fs.sort_values(by=['coef_lr'],ascending=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAEKCAYAAAAIO8L1AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAIABJREFUeJzt3Xt4HPV97/H3V3dblnyTZBvJd2SM\nuTgQYZJAEgghMWkOToA0kKRJaBt6CU0vJ6eFkzwkJc1p0/Skp01JUppS2rQNUCCtkxoI4RJCLmAZ\nMNj4IiHbsWzJknzR1brtfs8fOzJreWWtjGZnV/q8nmcf78z8dvY7Wms/mpnf/MbcHRERkdHyoi5A\nRESykwJCRERSUkCIiEhKCggREUlJASEiIikpIEREJCUFhIiIpKSAEBGRlBQQIiKSUkHUBUxURUWF\nL1u2LOoyRERyypYtWzrcvXIirwktIMzsHuD9QJu7n59iuQF/A7wP6AM+6e4vjLfeZcuWUV9fP9nl\niohMaWa2b6KvCfMQ073A+tMsvwaoDR63AN8MsRYREZmg0ALC3Z8BjpymyQbgXzzhF8AcM1sUVj0i\nIjIxUZ6krg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4O3heDvQCnUG7a8Z4nzwSo2YCfCRY/+nMBlqCPZhfI3EbyRGryN3R\nXCVHaQ9CpqPvkTi/sJXEX/V/7O6tZvYQcBWJL+LdwHMk7roFiXuCXAH8yN23mtmLJEZZbQJ+Osb7\n9ALnmdmWYD0fHqeubwAPmdmHgKeC14+4MqhBJGM0mqtIEjOb5e49ZjafxF7FZUF4zCDxpX1ZcO4i\nnXX1uPusSarrGWCDJ+5/LpIR2oMQOdkPzGwOUAR8yd1bAdz9uJl9gcR9fX+ZyYKCw2BfUzhIpmkP\nQkREUtJJahERSUkBISIiKSkgREQkJQWEiIikpIAQEZGUFBAiIpLS/wdQt5LguqrjZgAAAABJRU5E\nrkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1a2062eb10>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('alpha is:', 0.00073726292123262299)\n"
     ]
    }
   ],
   "source": [
    "mses = np.mean(lasso.mse_path_, axis = 1)\n",
    "plt.plot(np.log10(lasso.alphas_), mses) \n",
    "#plt.plot(np.log10(lasso.alphas_)*np.ones(3), [0.3, 0.4, 1.0])\n",
    "plt.xlabel('log(alpha)')\n",
    "plt.ylabel('mse')\n",
    "plt.show()    \n",
    "            \n",
    "print ('alpha is:', lasso.alpha_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
